
var WindLayout = new Object();

WindLayout = function() {
	this.rows = new Array();
}

WindLayout.prototype.getNumberOfRows = function() {
	return this.rows.length;
}

WindLayout.prototype.createRow = function() {
	var row = new WindLayoutRow();
	this.rows[this.rows.length] = row;
	return row;
}

WindLayout.prototype.getRow = function(index) {
	return this.rows[index];
}

WindLayoutRow = function() {
	this.cells = new Array();
}

WindLayoutRow.prototype.getNumberOfCells = function() {
	return this.cells.length;
}

WindLayoutRow.prototype.createCell = function() {
	var cell = new WindLayoutCell();
	this.cells[this.cell.length] = cell;
	return cell;
}

WindLayoutRow.prototype.getCell = function(index) {
	return this.cells[index];
}

WindLayoutCell = function() {
	this.models = new Array();
	this.colspan = 1;
}

WindLayoutCell.prototype.getNumberOfModels = function() {
	return this.models.length;
}

WindLayoutCell.prototype.addModel = function(model) {
	this.models[this.models.length] = model;
	return models;
}

WindLayoutCell.prototype.getModel = function(index) {
	return this.models[index];
}

WindLayoutCell.prototype.setColSpan = function(colspan) {
	this.colspan = colspan;
}

WindLayoutCell.prototype.getColSpan = function() {
	return this.colspan;
}

WindLayout.createModel = function() {
	var layoutModel = new WindLayoytModel();
	return layoutModel;
} 

WindLayout.createView = function(layoutModel) {
	var layoutView = new WindView();
	layoutView.setCssClass("WindLayout");

	if(layoutModel!=null) {
		for(var i=0; i<layoutModel.getNumberOfRows(); i++) {
			var rowModel = layoutModel.getRow(i);
			var rowView = WindLayout.createRowView(rowModel);
			layoutView.addView(rowView);
		}
	}
	
	layoutView.createRowView = function() {
		var rowView = WindLayout.createRowView(rowModel);
		layoutView.addView(rowView);
		return rowView;
	}
	
	layoutView.render = function() {
		var table = document.createElement("table");
		table.cellPadding = 0;
		table.cellSpacing = 0;
		layoutView.setHtmlElement(table);
		layoutView.applyViewAttributesToHtmlElement(table);
		layoutView.renderChildren(table);			
		return table;
	}
	
	return layoutView;
}

WindLayout.createRowView = function(rowModel) {
	var rowView = new WindView();
	rowView.setCssClass("WindLayoutRow");
	
	if(rowModel!=null) {
		for(var i=0; i<rowModel.getNumberOfCells(); i++) {
			var rowModel = rowModel.getCell(i);
			var cellView = WindLayout.createCellView(rowModel);
			rowView.addView(cellView);
		}
	}
	
	rowView.createCellView = function() {
		var cellView = WindLayout.createCellView();
		rowView.addView(cellView);
		return cellView;
	}
	
	rowView.render = function() {
		var tr = document.createElement("tr");
		rowView.setHtmlElement(tr);
		rowView.applyViewAttributesToHtmlElement(tr);
		rowView.renderChildren(tr);			
		return tr;
	}
	
	return rowView;
}


WindLayout.createCellView = function(cellModel) {
	var cellView = new WindView();
	cellView.setCssClass("WindLayoutCell");
	
	if(cellModel!=null) {
		for(var i=0; i<rowModel.getNumberOfCells(); i++) {
			var model = cellModel.getModel(i);
			var view = model.createView();
			cellView.addView(view);
		}
	}
	
	cellView.setColSpan = function(colSpan) {
		cellView.colSpan = colSpan;
	} 

	cellView.render = function() {
		var td = document.createElement("td");
		td.colSpan = cellView.colSpan;
		cellView.setHtmlElement(td);
		cellView.applyViewAttributesToHtmlElement(td);
		cellView.renderChildren(td);			
		return td;
	}
	
	return cellView;
}



